$(document).ready(function(){
	
	loadZoneStart();
	loadZoneEnd();
	setYear();
});


function setYear()
{

	var currentDate = new Date();
    var year = currentDate.getFullYear();
	year += 543;
	
	var selected="";
	var options = '';
	options += '<option value="">-- เลือกปี --</option>';
	for (var i = 0; i <= 3; i++) {
		options += '<option value="' + (year - i) + '" '+selected+'>' + (year - i) +  '</option>';
	}
	$("select[name=year]#inputYear").html(options);
	
}

function loadZoneStart() {
	$.ajax({
		url : "CS43004Srvl", 
		type : "POST",
		data : {
			process_type: "getZone"
		},
	//	anync:false,
		dataType:"JSON",
		success: function(data){
			var selected="";
			var options = '';
			options += '<option value="">-- เลือกเขต --</option>';
			for (var i = 0; i < data.values.length; i++) {
				options += '<option value="' + data.values[i] + '" '+selected+'>' + data.messages[i] +  '</option>';
			}
			$("select[name=zone_start]#inputZoneStart").html(options);
		}
	});
}

function loadZoneEnd() {
	$.ajax({
		url : "CS43004Srvl", 
		type : "POST",
		data : {
			process_type: "getZone" 
		},
	//	anync:false,
		dataType:"JSON",
		success: function(data){
			var selected="";
			var options = '';
			options += '<option value="">-- เลือกเขต --</option>';
			for (var i = 0; i < data.values.length; i++) {
				options += '<option value="' + data.values[i] + '" '+selected+'>' + data.messages[i] +  '</option>';
			}
			$("select[name=zone_end]#inputZoneEnd").html(options);
		}
	});
}

function printReport() {
	var vaMonth = $("#inputMonthStart").val();
	var vaYear = $("#inputYear").val();
	var vaZoneStart = $("#inputZoneStart").val();
	var vaZoneEnd = $("#inputZoneEnd").val();
	var vnUserId = $("#userId").val();
	var vnSiteId = $("#siteId").val();
	
	
	if(vaMonth.trim().length == 0 || vaYear.trim().length == 0 || vaZoneStart.trim().length == 0 
			|| vaZoneEnd.trim().length == 0 )
	{

		$("#modal_content").html("กรุณากรอกข้อมูลให้ครบถ้วน");
		$("#warningModal").modal();
		return;
	}else{

		var url = reporturl+"CS43004R.jsp?month="+vaMonth+"&siteid="+vnSiteId+"&user_id="+vnUserId+"&year="+vaYear+"&zoneidfrom="+vaZoneStart+"&zoneidto="+vaZoneEnd;
		window.open(url);

	}
}